#include "btform.h"
#include "ui_btform.h"

btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);

    ui->lineBox->hide();
    // 设置line1的动画效果
     line1Animal = new QPropertyAnimation(ui->line1, "geometry", this);
     line1Animal->setDuration(1500);
     line1Animal->setKeyValueAt(0, QRect(0, 15, 2, 0));
     line1Animal->setKeyValueAt(0.5, QRect(0, 0, 2, 15));
     line1Animal->setKeyValueAt(1, QRect(0, 15, 2, 0));
     line1Animal->setLoopCount(-1);
     line1Animal->start();
     // 设置line2的动画效果
     line2Animal = new QPropertyAnimation(ui->line2, "geometry", this);
     line2Animal->setDuration(1600);
     line2Animal->setKeyValueAt(0, QRect(7, 15, 2, 0));
     line2Animal->setKeyValueAt(0.5, QRect(7, 0, 2, 15));
     line2Animal->setKeyValueAt(1, QRect(7, 15, 2, 0));
     line2Animal->setLoopCount(-1);
     line2Animal->start();
     // 设置line3的动画效果
     line3Animal = new QPropertyAnimation(ui->line3, "geometry", this);
     line3Animal->setDuration(1700);
     line3Animal->setKeyValueAt(0, QRect(14, 15, 2, 0));
     line3Animal->setKeyValueAt(0.5, QRect(14, 0, 2, 15));
     line3Animal->setKeyValueAt(1, QRect(14, 15, 2, 0));
     line3Animal->setLoopCount(-1);
     line3Animal->start();
     // 设置line4的动画效果
     line4Animal = new QPropertyAnimation(ui->line4, "geometry", this);
     line4Animal->setDuration(1800);
     line4Animal->setKeyValueAt(0, QRect(21, 15, 2, 0));
     line4Animal->setKeyValueAt(0.5, QRect(21, 0, 2, 15));
     line4Animal->setKeyValueAt(1, QRect(21, 15, 2, 0));
     line4Animal->setLoopCount(-1);
     line4Animal->start();
}

btForm::~btForm()
{
    delete ui;
}

void btForm::seticon(const QString& btIcon, const QString& btText, int pageId)
{
    // 设置⾃定义按钮的图⽚、⽂字、以及id
     ui->btIcon->setPixmap(QPixmap(btIcon));
     ui->btText->setText(btText);
     this->pageId = pageId;
}

void btForm::clearBg()
{
    // 清除上⼀个按钮点击的背景效果,恢复之前的样式
     ui->btStyle->setStyleSheet("#btStyle:hover{ background:#D8D8D8;} ");
}

int btForm::getId() const
{
    return pageId;
}

void btForm::showAnimal()
{
    // 显⽰linebox, 设置颜⾊为绿⾊
    ui->lineBox->show();
}

void btForm::mousePressEvent(QMouseEvent *event)
{
     // 告诉编译器不要触发警告
     (void)event;
     // ⿏标点击之后，背景变为绿⾊，⽂字变为⽩⾊
     ui->btStyle->setStyleSheet("#btStyle{ background:rgb(30,206,154);}*{color:#F6F6F6;}");

     emit btClick(this->pageId); // 发送⿏标点击信号
}
